// 笔试强训day27:kotori和气球

#include <iostream>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    long long ans = n;
    int count = m - 1;
    while(count--)
    {
        ans = (ans * (n - 1)) % 109;
    }
    cout << ans << endl;
}